package com.groupbuying.provider.service.impl;

import com.groupbuying.provider.constants.CommonConstants;
import com.groupbuying.provider.constants.StoreVirtualOperConstants;
import com.groupbuying.provider.context.FilterContextHandler;
import com.groupbuying.provider.dao.StoreCapitalVirtualAccountDetailDao;
import com.groupbuying.provider.dto.StoreCapitalVirtualAccountDetailDTO;
import com.groupbuying.provider.service.StoreCapitalVirtualAccountDetailService;
import com.groupbuying.provider.utils.PageUtils;
import com.groupbuying.provider.utils.Query;
import com.groupbuying.provider.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StoreCapitalVirtualAccountDetailServiceImpl implements StoreCapitalVirtualAccountDetailService {
    @Autowired
    private StoreCapitalVirtualAccountDetailDao storeCapitalVirtualAccountDetailDao;

    @Override
    public R getListByPage(Map<String, Object> params) {
        params.put("delflag", CommonConstants.COMMON_FLAG_UNDEL);
        params.put("providerId", FilterContextHandler.getName());
        params.put("sort", "createTime");
        params.put("order", "desc");
        Query query = new Query(params);
        List<StoreCapitalVirtualAccountDetailDTO> list = storeCapitalVirtualAccountDetailDao.getListByPage(query);
        for (StoreCapitalVirtualAccountDetailDTO dto : list) {
            switch (dto.getBusinessType()) {
                case StoreVirtualOperConstants.PREFERENTIAL_ORDER_REFUND: {
                    dto.setBusinessType("优惠买单订单退款");
                }
                break;
                case StoreVirtualOperConstants.PREFERENTIAL_ORDER_SETTLE: {
                    dto.setBusinessType("优惠买单订单分账");
                }
                break;
                case StoreVirtualOperConstants.ORDER_WITHDRAW: {
                    dto.setBusinessType("商家提现");
                }
                case StoreVirtualOperConstants.OPTIMAL_STORE_ORDER_REFUND:{
                    dto.setBusinessType("够样优店订单退款");
                }
                case StoreVirtualOperConstants.OPTIMAL_STORE_ORDER_SETTLE:{
                    dto.setBusinessType("够样优店订单分账");
                }
                break;
            }
        }

        params.remove("limit");
        params.remove("page");
        query = new Query(params);
        List<StoreCapitalVirtualAccountDetailDTO> totalList = storeCapitalVirtualAccountDetailDao.getListByPage(query);
        PageUtils pageUtil = new PageUtils(list, totalList.size());
        return R.ok().put("page", pageUtil);
    }

    @Override
    public PageUtils getFinancialPwdList(Map<String, Object> params) {
        params.put("delflag", CommonConstants.COMMON_FLAG_UNDEL);
        params.put("providerId", FilterContextHandler.getName());
        Query query = new Query(params);
        List<Map<String,Object>> list = storeCapitalVirtualAccountDetailDao.getFinancialPwdList(query);
        int count = storeCapitalVirtualAccountDetailDao.countFinancialPwd(params);
        PageUtils pageUtil = new PageUtils(list, count);
        return pageUtil;
    }


}
